package com.example.config.es.template.impl;

import com.example.config.es.template.SyncStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.stereotype.Component;

// 强一致性策略（同步执行）
@Component("strongConsistency")
public class StrongConsistencyStrategy<T,ID> implements SyncStrategy<T,ID> {
    @Autowired
    private ElasticsearchOperations esOperations;

    @Override
    public <T> void syncSaveOrUpdate(T entity) {
        esOperations.save(entity); // 同步保存到ES
    }

    @Override
    public <T> void syncDelete(Class<T> entityClass, ID id) {
        esOperations.delete(id.toString(),entityClass); // 同步从ES删除
    }
}
